package Modellus.WinUI.ExampleTable;

import Modellus.Core.Animator.IPropertyProxy;
import Modellus.Core.Model.IModel;
import Modellus.WinUI.Animator.PropertyPainter;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class PropertyCellRenderer extends DefaultTableCellRenderer implements TableCellRenderer
{
	private IPropertyProxy _variable;
	private PropertyPainter _propertyPainter;
	IModel _model;

	public PropertyCellRenderer(IModel model, IPropertyProxy variable)
	{
		_variable = variable;
		_propertyPainter = new PropertyPainter();
		setText("0");
		_model = model;
	}

	@Override
	public void paint(Graphics graphics)
	{
		_propertyPainter.setFontColor(Color.BLACK);
		_propertyPainter.paint((Graphics2D) graphics, new Point(getWidth() / 2, 0), _variable, 0, 0, _model.getAreCasesEnabled(), true, false, true, false);
	}

	public void setVariable(IPropertyProxy variable)
	{
		_variable = variable;
	}

	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
	{
		return this;
	}
}
